package com.xuyuan.interview.scene.coupon;

import com.xuyuan.interview.scene.api.CouponCondition;
import com.xuyuan.interview.scene.entity.Order;
import com.xuyuan.interview.scene.entity.Product;

import java.math.BigDecimal;

public class FullRedutionCoupon extends CouponCondition {
    private BigDecimal threshold;
    private BigDecimal reductionAmount;

    @Override
    public String getCouponName() {
        return this.getClass().getSimpleName();
    }

    @Override
    public Order applyDiscount(Order order) {
        if (order.getTotalPrice().compareTo(this.threshold) != -1) {
            order.setTotalPrice(order.getTotalPrice().subtract(this.reductionAmount));
        }
        return order;
    }

    @Override
    public boolean isSatisfied(Order order, Product product, int userLevel) {
        if (order.getTotalPrice().compareTo(this.threshold) == -1) {
            return false;
        }
        return super.isSatisfied(order, product, userLevel);
    }

    @Override
    public BigDecimal findPriority(Order order) {
        return this.applyDiscount(order).getTotalPrice();
    }
}
